package com.compomics.proteocloud.model;

import com.compomics.proteocloud.db.accessor.Pepnovohit;
import com.compomics.proteocloud.io.MascotGenericFile;
import com.compomics.proteocloud.starter.CloudTools;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Consists of a de novo hit set.
 *
 * @author Thilo Muth
 */
public class DenovoHitSet {

    /**
     * The spectrumTitle
     */
    private String spectrumTitle;

    /**
     * The spectrum id.
     */
    private int spectrumId;

    /**
     * The actual spectrum file.
     */
    private MascotGenericFile mgf;
    
    /**
     * The denovo hits.
     */
    private List<Pepnovohit> denovoHits;

    public DenovoHitSet(String spectrumTitle, int spectrumId, Pepnovohit hit) throws IOException, SQLException {
        this.spectrumTitle = spectrumTitle;
        this.spectrumId = spectrumId;
        this.denovoHits = new ArrayList<Pepnovohit>();
        this.denovoHits.add(hit);
    }

    /**
     * Returns the spectrum title.
     * @return The spectrum title.
     */
    public String getSpectrumTitle() {
        return spectrumTitle;
    }

    /**
     * Returns the spectrum id.
     * @return The spectrum id.
     */
    public int getSpectrumId() {
        return spectrumId;
    }

    /**
     * Returns the de novo hits.
     * @return The De novo hits.
     */
    public List<Pepnovohit> getDenovoHits() {
        return denovoHits;
    }

    /**
     * Adds the de novo hit to the list.
     * @param hit Pepnovohit
     */
    public void addHit(Pepnovohit hit){
        denovoHits.add(hit);
    }

    public MascotGenericFile getMascotGenericFile() throws SQLException, IOException {
        // Lazy loading
        if(mgf == null) {
            this.mgf = CloudTools.getInstance().getSpectrumFromSpectrumID(spectrumId);
        }
        return mgf;
    }
}
